Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Async Profiler Feature #203

Merged
merged 27 commits into from
Oct 28, 2024
Merged

Support Async Profiler Feature #203

merged 27 commits into from
Oct 28, 2024

Conversation

zhengziyi0117
Copy link
Contributor

@zhengziyi0117 zhengziyi0117 commented Oct 24, 2024

Add the sub-command profiling async for async-profiler query API

Here are some examples

# Create a async-profiler task
swctl profiling async create --service-name=service-name --duration=60 --events=cpu,alloc \ 
	--instance-name-list=instance-name1,instance-name2 --exec-args=interval=50ms
# Query all async-profiler tasks
swctl profiling async list --service-name=service-name
# Query task progress, including task logs and successInstances and errorInstances
swctl profiling async progress --task-id=task-id
# Query the flame graph produced by async-profiler
swctl profiling async analysis --service-name=service-name --task-id=task-id \
	--instance-name-list=instance-name1,instance-name2 --event=execution_sample

@wu-sheng wu-sheng requested a review from mrproliu October 24, 2024 13:37
@wu-sheng
Copy link
Member

@mrproliu We don't have backend ready, as we need this to verify the backend. Please review from codes as much as possible.

@wu-sheng wu-sheng added this to the 0.15.0 milestone Oct 24, 2024
@wu-sheng wu-sheng added the feature this pull request provides new feature label Oct 24, 2024
@wu-sheng
Copy link
Member

@zhengziyi0117 Please fix CI.

var Command = &cli.Command{
Name: "asyncprofiler",
Usage: "async profiler related sub-command",
UsageText: `todo`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the usage text.

)

var Command = &cli.Command{
Name: "asyncprofiler",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this command is under the profiling command, should we remove the profiler suffix?
For now, the command should be: swctl profiling asyncprofiler, I think it could be: swctl profiling async is much clear, what do you think?

eventTypes = append(eventTypes, query.AsyncProfilerEventType(upperCaseEvent))
}

execArgs := ctx.String("exec-args")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the type of execArgs as *string, and assign the value when judgment the ctx.String is not an empty string? You will get an empty string even if the exec-args is not declared.

Comment on lines 54 to 58
eventTypes := make([]query.AsyncProfilerEventType, 0)
for _, event := range events {
upperCaseEvent := strings.ToUpper(event)
eventTypes = append(eventTypes, query.AsyncProfilerEventType(upperCaseEvent))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is best to create an enum model to obtain the event types, and the CLI should verify whether we have an enum value. You can refer to https://github.com/apache/skywalking-cli/blob/master/internal/model/type.go. However, the type you choose should be a slice, which is slightly different from the existing reference.

Comment on lines 34 to 38
&cli.StringFlag{
Name: "event",
Usage: "which event types this task needs to collect.",
Required: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum should be a new model. Instant of a string value without any type check.


request := &query.AsyncProfilerAnalyzationRequest{
TaskID: ctx.String("task-id"),
InstanceIds: ctx.StringSlice("service-instance-ids"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use String and split by self.

Comment on lines 44 to 46
startTime := ctx.Int64("start-time")
endTime := ctx.Int64("end-time")
limit := ctx.Int("limit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us declare the startTime, endTime, and limit as *int64 or *int first, otherwise the value will be 0.


var getTaskProgressCommand = &cli.Command{
Name: "progress",
Aliases: []string{"logs", "p"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be used as swctl profiling asyncprofiler logs? I think it's a difference in the meaning of progress.

@mrproliu
Copy link
Contributor

@zhengziyi0117 Also, please update the CHANGES.md

@lujiajing1126
Copy link

lujiajing1126 commented Oct 26, 2024

Pls run golangci-lint locally to ensure it can pass CI

instanceNameFlagName = "instance-name"
destInstanceIDFlagName = "dest-instance-id"
destInstanceNameFlagName = "dest-instance-name"
InstanceIDSliceFlagName = "instance-id-slice"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use "list" instant of "slice"

Examples:
1. Query the flame graph produced by async-profiler
$ swctl profiling async analysis --service-name=service-name --task-id=task-id \
--service-instance-ids=instance-name1,instance-name2 --event=execution_sample`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update all incorrect name of the parameter.

@wu-sheng
Copy link
Member

Could you update the PR description to add which commands are you adding, and put some examples(input and output) in it?

@mrproliu mrproliu merged commit bce7faa into apache:master Oct 28, 2024
7 checks passed
@wu-sheng wu-sheng mentioned this pull request Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature this pull request provides new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants